package com.medicalfee.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.medicalfee.dao.StuffInfo;
import com.medicalfee.dao.StuffInfoDAO;

public class InsertOrUpdateStuffController extends AbstractFormController {
	public InsertOrUpdateStuffController() {
		setCommandClass(StuffInfo.class);
	}

	private StuffInfoDAO stuffInfoDao;

	public void setStuffInfoDao(StuffInfoDAO stuffInfoDao) {
		this.stuffInfoDao = stuffInfoDao;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException be)
			throws Exception {
		// TODO Auto-generated method stub
		String data = request.getParameter("data");
		JSONObject json = JSONObject.fromObject(data);
		StuffInfo stuff = (StuffInfo) JSONObject.toBean(json, StuffInfo.class);
		stuffInfoDao.insertOrUpdateStuff(stuff);
		return null;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException be) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
